{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#导包\n",
    "from sklearn.cluster import KMeans\n",
    "from sklearn import preprocessing\n",
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>国家</th>\n",
       "      <th>2019国际排名</th>\n",
       "      <th>2018世界杯排名</th>\n",
       "      <th>2015亚洲杯排名</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>中国</td>\n",
       "      <td>73</td>\n",
       "      <td>40</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>日本</td>\n",
       "      <td>60</td>\n",
       "      <td>15</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩国</td>\n",
       "      <td>61</td>\n",
       "      <td>19</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>伊朗</td>\n",
       "      <td>34</td>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>沙特</td>\n",
       "      <td>67</td>\n",
       "      <td>26</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>伊拉克</td>\n",
       "      <td>91</td>\n",
       "      <td>40</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>卡塔尔</td>\n",
       "      <td>101</td>\n",
       "      <td>40</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>阿联酋</td>\n",
       "      <td>81</td>\n",
       "      <td>40</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>乌兹别克斯坦</td>\n",
       "      <td>88</td>\n",
       "      <td>40</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>泰国</td>\n",
       "      <td>122</td>\n",
       "      <td>40</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>越南</td>\n",
       "      <td>102</td>\n",
       "      <td>50</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>阿曼</td>\n",
       "      <td>87</td>\n",
       "      <td>50</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>朝鲜</td>\n",
       "      <td>110</td>\n",
       "      <td>50</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>印尼</td>\n",
       "      <td>164</td>\n",
       "      <td>50</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>澳洲</td>\n",
       "      <td>40</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>叙利亚</td>\n",
       "      <td>76</td>\n",
       "      <td>40</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>约旦</td>\n",
       "      <td>118</td>\n",
       "      <td>50</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>科威特</td>\n",
       "      <td>160</td>\n",
       "      <td>50</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        国家  2019国际排名  2018世界杯排名  2015亚洲杯排名\n",
       "0       中国        73         40          7\n",
       "1       日本        60         15          5\n",
       "2       韩国        61         19          2\n",
       "3       伊朗        34         18          6\n",
       "4       沙特        67         26         10\n",
       "5      伊拉克        91         40          4\n",
       "6      卡塔尔       101         40         13\n",
       "7      阿联酋        81         40          6\n",
       "8   乌兹别克斯坦        88         40          8\n",
       "9       泰国       122         40         17\n",
       "10      越南       102         50         17\n",
       "11      阿曼        87         50         12\n",
       "12      朝鲜       110         50         14\n",
       "13      印尼       164         50         17\n",
       "14      澳洲        40         30          1\n",
       "15     叙利亚        76         40         17\n",
       "16      约旦       118         50          9\n",
       "17     科威特       160         50         15"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#读取数据\n",
    "data=pd.read_csv('team_cluster_data.csv',encoding='gbk')\n",
    "data#可以看到是18只球队  每一列是其三次比赛的排名  然后根据排名来聚类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>2019国际排名</th>\n",
       "      <th>2018世界杯排名</th>\n",
       "      <th>2015亚洲杯排名</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>73</td>\n",
       "      <td>40</td>\n",
       "      <td>7</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>60</td>\n",
       "      <td>15</td>\n",
       "      <td>5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>61</td>\n",
       "      <td>19</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>34</td>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>67</td>\n",
       "      <td>26</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>91</td>\n",
       "      <td>40</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>101</td>\n",
       "      <td>40</td>\n",
       "      <td>13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>81</td>\n",
       "      <td>40</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>88</td>\n",
       "      <td>40</td>\n",
       "      <td>8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>122</td>\n",
       "      <td>40</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>102</td>\n",
       "      <td>50</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>87</td>\n",
       "      <td>50</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>110</td>\n",
       "      <td>50</td>\n",
       "      <td>14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>164</td>\n",
       "      <td>50</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>40</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>76</td>\n",
       "      <td>40</td>\n",
       "      <td>17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>118</td>\n",
       "      <td>50</td>\n",
       "      <td>9</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>160</td>\n",
       "      <td>50</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    2019国际排名  2018世界杯排名  2015亚洲杯排名\n",
       "0         73         40          7\n",
       "1         60         15          5\n",
       "2         61         19          2\n",
       "3         34         18          6\n",
       "4         67         26         10\n",
       "5         91         40          4\n",
       "6        101         40         13\n",
       "7         81         40          6\n",
       "8         88         40          8\n",
       "9        122         40         17\n",
       "10       102         50         17\n",
       "11        87         50         12\n",
       "12       110         50         14\n",
       "13       164         50         17\n",
       "14        40         30          1\n",
       "15        76         40         17\n",
       "16       118         50          9\n",
       "17       160         50         15"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#特征选择  “国家”这个不是特征  后面三列才是我们要训练的特征\n",
    "train_x=data[['2019国际排名','2018世界杯排名','2015亚洲杯排名']]\n",
    "train_x#这个就是我们要训练的数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MinMaxScaler(copy=True, feature_range=(0, 1))"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#数据规范化一下 用[0,1]规范化\n",
    "min_max_scaler=preprocessing.MinMaxScaler()\n",
    "min_max_scaler#feature_range=(0, 1)这里默认是转到0-1  也可以更改"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[0.3       , 0.71428571, 0.375     ],\n",
       "       [0.2       , 0.        , 0.25      ],\n",
       "       [0.20769231, 0.11428571, 0.0625    ],\n",
       "       [0.        , 0.08571429, 0.3125    ],\n",
       "       [0.25384615, 0.31428571, 0.5625    ],\n",
       "       [0.43846154, 0.71428571, 0.1875    ],\n",
       "       [0.51538462, 0.71428571, 0.75      ],\n",
       "       [0.36153846, 0.71428571, 0.3125    ],\n",
       "       [0.41538462, 0.71428571, 0.4375    ],\n",
       "       [0.67692308, 0.71428571, 1.        ],\n",
       "       [0.52307692, 1.        , 1.        ],\n",
       "       [0.40769231, 1.        , 0.6875    ],\n",
       "       [0.58461538, 1.        , 0.8125    ],\n",
       "       [1.        , 1.        , 1.        ],\n",
       "       [0.04615385, 0.42857143, 0.        ],\n",
       "       [0.32307692, 0.71428571, 1.        ],\n",
       "       [0.64615385, 1.        , 0.5       ],\n",
       "       [0.96923077, 1.        , 0.875     ]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#用这个min_max_scaler对训练数据归一化\n",
    "train_x=min_max_scaler.fit_transform(train_x)\n",
    "train_x#可以看到本来是18行3列的数据  已经全部归一化了  还是18行3列  数据类型是ndarray"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'numpy.ndarray'> (18, 3)\n"
     ]
    }
   ],
   "source": [
    "print(type(train_x),train_x.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "KMeans(algorithm='auto', copy_x=True, init='k-means++', max_iter=300,\n",
       "       n_clusters=3, n_init=10, n_jobs=None, precompute_distances='auto',\n",
       "       random_state=None, tol=0.0001, verbose=0)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#导入模型并训练预测\n",
    "kmeans = KMeans(n_clusters=3)\n",
    "kmeans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "predict_y: <class 'numpy.ndarray'> (18,)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([0, 2, 2, 2, 2, 0, 1, 0, 0, 1, 1, 1, 1, 1, 2, 1, 0, 1], dtype=int32)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#训练预测\n",
    "predict_y=kmeans.fit_predict(train_x)\n",
    "print(\"predict_y:\",type(predict_y),predict_y.shape)\n",
    "predict_y#可以看到是分成了0 1 2三类 这就是聚类的效果"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>国家</th>\n",
       "      <th>2019国际排名</th>\n",
       "      <th>2018世界杯排名</th>\n",
       "      <th>2015亚洲杯排名</th>\n",
       "      <th>球队分类</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>中国</td>\n",
       "      <td>73</td>\n",
       "      <td>40</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>日本</td>\n",
       "      <td>60</td>\n",
       "      <td>15</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩国</td>\n",
       "      <td>61</td>\n",
       "      <td>19</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>伊朗</td>\n",
       "      <td>34</td>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>沙特</td>\n",
       "      <td>67</td>\n",
       "      <td>26</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>伊拉克</td>\n",
       "      <td>91</td>\n",
       "      <td>40</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>卡塔尔</td>\n",
       "      <td>101</td>\n",
       "      <td>40</td>\n",
       "      <td>13</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>阿联酋</td>\n",
       "      <td>81</td>\n",
       "      <td>40</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>乌兹别克斯坦</td>\n",
       "      <td>88</td>\n",
       "      <td>40</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>泰国</td>\n",
       "      <td>122</td>\n",
       "      <td>40</td>\n",
       "      <td>17</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>越南</td>\n",
       "      <td>102</td>\n",
       "      <td>50</td>\n",
       "      <td>17</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>阿曼</td>\n",
       "      <td>87</td>\n",
       "      <td>50</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>朝鲜</td>\n",
       "      <td>110</td>\n",
       "      <td>50</td>\n",
       "      <td>14</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>印尼</td>\n",
       "      <td>164</td>\n",
       "      <td>50</td>\n",
       "      <td>17</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>澳洲</td>\n",
       "      <td>40</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>叙利亚</td>\n",
       "      <td>76</td>\n",
       "      <td>40</td>\n",
       "      <td>17</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>约旦</td>\n",
       "      <td>118</td>\n",
       "      <td>50</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>科威特</td>\n",
       "      <td>160</td>\n",
       "      <td>50</td>\n",
       "      <td>15</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        国家  2019国际排名  2018世界杯排名  2015亚洲杯排名  球队分类\n",
       "0       中国        73         40          7     0\n",
       "1       日本        60         15          5     2\n",
       "2       韩国        61         19          2     2\n",
       "3       伊朗        34         18          6     2\n",
       "4       沙特        67         26         10     2\n",
       "5      伊拉克        91         40          4     0\n",
       "6      卡塔尔       101         40         13     1\n",
       "7      阿联酋        81         40          6     0\n",
       "8   乌兹别克斯坦        88         40          8     0\n",
       "9       泰国       122         40         17     1\n",
       "10      越南       102         50         17     1\n",
       "11      阿曼        87         50         12     1\n",
       "12      朝鲜       110         50         14     1\n",
       "13      印尼       164         50         17     1\n",
       "14      澳洲        40         30          1     2\n",
       "15     叙利亚        76         40         17     1\n",
       "16      约旦       118         50          9     0\n",
       "17     科威特       160         50         15     1"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#然后再把聚类的效果 和原本特征数据 组成一个dataframe\n",
    "# 合并聚类结果，插入到原数据中\n",
    "result = pd.concat((data,pd.DataFrame(data=predict_y,columns=['球队分类'])),axis=1) #这里的data是最开始之前没有经过归一化的data\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "#将文件导出\n",
    "result.to_csv('Kmeans聚成3中球队的结果.csv')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 0, 0, 0, 0, 1, 2, 1, 1, 2, 2, 1, 2, 2, 0, 2, 1, 2])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#同样可以用GMM聚类算法 GaussianMixtureModel  即高斯混合模型\n",
    "from sklearn.mixture import GaussianMixture\n",
    "gmm_model = GaussianMixture(n_components=3, covariance_type=\"full\")#n_components=3表示聚成3类 covariance_type表示完全协方差矩阵\n",
    "gmm_pre_y=gmm_model.fit_predict(train_x)\n",
    "gmm_pre_y#可以看到同样聚成了3类"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>国家</th>\n",
       "      <th>2019国际排名</th>\n",
       "      <th>2018世界杯排名</th>\n",
       "      <th>2015亚洲杯排名</th>\n",
       "      <th>球队分类</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>中国</td>\n",
       "      <td>73</td>\n",
       "      <td>40</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>日本</td>\n",
       "      <td>60</td>\n",
       "      <td>15</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>韩国</td>\n",
       "      <td>61</td>\n",
       "      <td>19</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>伊朗</td>\n",
       "      <td>34</td>\n",
       "      <td>18</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>沙特</td>\n",
       "      <td>67</td>\n",
       "      <td>26</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>伊拉克</td>\n",
       "      <td>91</td>\n",
       "      <td>40</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>卡塔尔</td>\n",
       "      <td>101</td>\n",
       "      <td>40</td>\n",
       "      <td>13</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>阿联酋</td>\n",
       "      <td>81</td>\n",
       "      <td>40</td>\n",
       "      <td>6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>乌兹别克斯坦</td>\n",
       "      <td>88</td>\n",
       "      <td>40</td>\n",
       "      <td>8</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>泰国</td>\n",
       "      <td>122</td>\n",
       "      <td>40</td>\n",
       "      <td>17</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>越南</td>\n",
       "      <td>102</td>\n",
       "      <td>50</td>\n",
       "      <td>17</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>阿曼</td>\n",
       "      <td>87</td>\n",
       "      <td>50</td>\n",
       "      <td>12</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>朝鲜</td>\n",
       "      <td>110</td>\n",
       "      <td>50</td>\n",
       "      <td>14</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>印尼</td>\n",
       "      <td>164</td>\n",
       "      <td>50</td>\n",
       "      <td>17</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>澳洲</td>\n",
       "      <td>40</td>\n",
       "      <td>30</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>叙利亚</td>\n",
       "      <td>76</td>\n",
       "      <td>40</td>\n",
       "      <td>17</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>约旦</td>\n",
       "      <td>118</td>\n",
       "      <td>50</td>\n",
       "      <td>9</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>科威特</td>\n",
       "      <td>160</td>\n",
       "      <td>50</td>\n",
       "      <td>15</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        国家  2019国际排名  2018世界杯排名  2015亚洲杯排名  球队分类\n",
       "0       中国        73         40          7     1\n",
       "1       日本        60         15          5     0\n",
       "2       韩国        61         19          2     0\n",
       "3       伊朗        34         18          6     0\n",
       "4       沙特        67         26         10     0\n",
       "5      伊拉克        91         40          4     1\n",
       "6      卡塔尔       101         40         13     2\n",
       "7      阿联酋        81         40          6     1\n",
       "8   乌兹别克斯坦        88         40          8     1\n",
       "9       泰国       122         40         17     2\n",
       "10      越南       102         50         17     2\n",
       "11      阿曼        87         50         12     1\n",
       "12      朝鲜       110         50         14     2\n",
       "13      印尼       164         50         17     2\n",
       "14      澳洲        40         30          1     0\n",
       "15     叙利亚        76         40         17     2\n",
       "16      约旦       118         50          9     1\n",
       "17     科威特       160         50         15     2"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#同样可以将结果拼接\n",
    "gmm_result = pd.concat((data,pd.DataFrame(data=gmm_pre_y,columns=['球队分类'])),axis=1) #这里的data是最开始之前没有经过归一化的data\n",
    "gmm_result"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
